using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class FormViewByCode : System.Web.UI.Page
{
    FormView formView;
    protected void Page_Load(object sender, EventArgs e)
    {


        formView = new FormView();
        formView.AllowPaging = true;
        formView.PageIndexChanging +=  new FormViewPageEventHandler(formView_PageIndexChanging);
        formView.HeaderText = "Account Details";
        formView.HeaderStyle.Font.Bold = true;
        this.form1.Controls.Add(formView);         
        
        if (!IsPostBack)
        {
            FillData(formView);
        }
    }

    void formView_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {


        formView.PageIndex = e.NewPageIndex;
        FillData(formView);
    }
    void FillData(FormView formView)
    {
        SqlDataSource sqlDataSource =
        new SqlDataSource();
        sqlDataSource.ConnectionString =
        WebConfigurationManager.ConnectionStrings[
        "RecruitVietnamDbConnectionString"].ConnectionString;
        sqlDataSource.SelectCommand =
        "Select Email,CompanyName,ContactName," +
        "Address,Phone from tblRCAccounts";
        formView.DataSource = sqlDataSource;
        formView.DataBind();
    }
}
